package com.atguigu.guli.service.edu.controller.api;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Chapter;
import com.atguigu.guli.service.edu.entity.Course;
import com.atguigu.guli.service.edu.entity.query.CourseApiQuery;
import com.atguigu.guli.service.edu.entity.vo.CourseDetailsVo;
import com.atguigu.guli.service.edu.service.ChapterService;
import com.atguigu.guli.service.edu.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2021-06-24
 */
@Api(tags = "客户端课程信息")
@CrossOrigin
@RestController
@RequestMapping("/api/edu/course")
public class ApiCourseController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private ChapterService chapterService;

    // 查询讲师下的所有课程
    @ApiOperation(value = "根据讲师id查询课程")
    @GetMapping("getCourseByTeacherId/{courseId}")
    public R getCourseByTeacherId(@PathVariable("courseId") String courseId) {
        List<Course> courses = courseService.getCourseByTeacherId(courseId);
        return R.ok().data("items", courses);
    }

    // 带条件查询的课程列表
    @ApiOperation(value = "带条件查询的课程列表")
    @GetMapping("getCourseList")
    public R getCourseList(CourseApiQuery courseApiQuery) {
        List<Course> courses = courseService.getCourseList(courseApiQuery);
        return R.ok().data("items", courses);
    }

    // 查询课程详细信息 + 讲师信息
    @ApiOperation(value = "查询课程详情")
    @GetMapping("getCourseDetails/{courseId}")
    public R getCourseDetails(@PathVariable String courseId) {
        CourseDetailsVo courseDetails = courseService.getCourseDetails(courseId);
        return R.ok().data("item", courseDetails);
    }

    // 查询课程下的所有章和小节
    @ApiOperation(value = "查询章和小节")
    @GetMapping("getChapterAndVideoAll/{courseId}")
    public R getChapterAndVideoAll(@PathVariable("courseId") String courseId) {
        List<Chapter> chapters = chapterService.getChaptersAndVideoS(courseId);
        return R.ok().data("items", chapters);
    }
}